/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import Entities.Actor;
import Entities.Actor_Movie_Entity;

import java.util.Date;
import javax.persistence.*;
import java.util.List;

/**
 *
 * @author sebastian
 */
public class ActorService {

    protected EntityManager em;

    public ActorService(EntityManager em) {
        this.em = em;
    }

    public Actor createActor(Long ID, String name, String lastName, 
        String picture, Date birthday, String birthPlace,
        Actor_Movie_Entity actorMovieEntity) {
        Actor actor = new Actor(ID);
        actor.setName(name);
        actor.setLastName(lastName);
        actor.setPicture(picture);
        actor.setBirthDate(birthday);
        actor.setBirthPlace(birthPlace);
        actor.setActorMovieEntity(actorMovieEntity);
        
        em.persist(actor);
        
        return actor;
    }
    
    
    public void updateActor(Long ID, String name, String lastName, 
        String picture, Date birthday, String birthPlace,
        Actor_Movie_Entity actorMovieEntity) {
        Actor actor = findActor(ID);
        actor.setName(name);
        actor.setLastName(lastName);
        actor.setPicture(picture);
        actor.setBirthDate(birthday);
        actor.setBirthPlace(birthPlace);
        actor.setActorMovieEntity(actorMovieEntity);
        
        em.persist(actor);
    }   
        
    public void removeActor(Long ID) {
        Actor actor = findActor(ID);
        if (actor != null) {
            em.remove(actor);
        }
    }

    public Actor findActor(Long ID) {
        return em.find(Actor.class, ID);
    }
 
      public Actor findMoviesActor(Long ID) {
        return em.find(Actor.class, ID);
    }

  
}

